<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>129-动画-匀速动画防止多次点击.html</title>
	<style>
	*{
			margin: 0;
			padding: 0;
		}
		#box{
			position: absolute;
			top: 50px;
			left: 0;
			width: 100px;
			height: 100px;
			background:skyblue;
			transition: all 0.5s linear;
		}
		.line{
			width: 1px;
			height: 400px;
			background: #000;
			position: absolute;
			top: 0;
			left: 400px;
		}
	</style>
</head>
<body>
	<button id="btn">开始动画</button>
	<div id="box"></div>
	<div class="line"></div>
</body>
<script>
	var oBtn = document.getElementById('btn');
	var oBox = document.getElementById('box');
	var timer = 0;

	oBtn.onclick = function(){
		// oBox.style.left = "400px";
		clearInterval(timer);
		timer = setInterval(function(){
			console.log('timer' + timer + "is running");
			if(oBox.offsetLeft == 400){
				clearInterval(timer);
			}else{
				oBox.style.left = oBox.offsetLeft + 100 +"px";
			}
			
		},30)
	}
</script>
</html>